﻿using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.Log;

namespace UtilZ.Tool.HostQuery
{
    internal class Program
    {
        private static System.Threading.Mutex _globalMutex = null;

        static void Main(string[] args)
        {
            try
            {
                if (!ProcessEx.TryCreataSingleProcessMutex(true, "13C6E6DD-3FEC-4D70-AEFC-433004B543EE", out _globalMutex))
                {
                    Console.WriteLine("Host服务已启动,不能重复启动,按任意键后程序退出.");
                    Console.ReadKey();
                    return;
                }

                using var hostBll = new QueryCore();
                //hostBll.GetCrushProcessIdList();
                hostBll.Start();

                if (EnvironmentEx.IsWindowPlatform())
                {
#pragma warning disable CA1416
                    ConsoleEx.HideConsole(Console.Title);
#pragma warning restore CA1416
                }

                Console.WriteLine("q exit");
                ConsoleKeyInfo consoleKey;
                while (true)
                {
                    consoleKey = Console.ReadKey();
                    if (consoleKey.Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Loger.Fatal(ex);
            }

            if (_globalMutex != null)
            {
                _globalMutex.Dispose();
            }
        }
    }
}